home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Info-Mac 4
/
Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso
/
Development
/
General
/
PTR-TCL v2.1
/
3) inherited fixer
/
main.c
< prev
next >
Wrap
Text File
|
1994-01-15
|
3KB
|
181 lines
/*
* main.c
*/
extern short ReadClasses ( unsigned char * name ) ;
void Idle ( void ) ;
void Message ( unsigned char * ) ;
void Try ( short code ) ;
unsigned char * folder_to_munge = "\pTO MUNGE" ;
unsigned char * message_file = "\pMESSAGES" ;
unsigned char * class_file = "\p CLASSLIST" ;
Handle windowText = NULL ;
WindowPtr window = NULL ;
short vRefNum = 0 ;
Boolean done = 0 ;
extern void MungeFolder ( long parID ) ;
void
Try ( short code ) {
if ( code ) {
DebugStr ( "\pFailure!" ) ;
}
}
static void
InitMac ( ) {
InitGraf ( & qd . thePort ) ;
InitFonts ( ) ;
InitWindows ( ) ;
InitMenus ( ) ;
TEInit ( ) ;
InitDialogs ( NULL ) ;
}
static void
UpdateWindow ( ) {
Rect r = window -> portRect ;
InsetRect ( & r , 3 , 3 ) ;
TextFont ( GetAppFont ( ) ) ;
TextSize ( GetDefFontSize ( ) ) ;
HLock ( windowText ) ;
TextBox ( * windowText , GetHandleSize ( windowText ) , & r , teJustLeft ) ;
HUnlock ( windowText ) ;
}
static void
Click ( EventRecord * er ) {
WindowPtr win ;
short code ;
Rect limit = ( * GetGrayRgn ( ) ) -> rgnBBox ;
InsetRect ( & limit , 3 , 3 ) ;
code = FindWindow ( er -> where , & win ) ;
switch ( code ) {
case inSysWindow :
SystemClick ( er , win ) ;
break ;
case inDrag :
DragWindow ( win , er -> where , & limit ) ;
break ;
}
}
void
Idle ( ) {
EventRecord er ;
WaitNextEvent ( -1 , & er , 0L , NULL ) ;
switch ( er . what ) {
case mouseDown :
Click ( & er ) ;
break ;
case updateEvt :
SetPort ( window ) ;
BeginUpdate ( window ) ;
EraseRect ( & ( window -> portRect ) ) ;
UpdateWindow ( ) ;
EndUpdate ( window ) ;
break ;
}
}
static void
SetWindowText ( unsigned char * string ) {
PtrToXHand ( string + 1 , windowText , * string ) ;
SetPort ( window ) ;
UpdateWindow ( ) ;
}
void
Message ( unsigned char * message ) {
static short refNum = 0 ;
long len ;
static unsigned long last = 0 ;
do {
Idle ( ) ;
} while ( TickCount ( ) < last + 5 ) ;
last = TickCount ( ) ;
if ( ! message ) {
if ( refNum ) {
FSClose ( refNum ) ;
FlushVol ( NULL , 0 ) ;
}
refNum = 0 ;
return ;
}
if ( ! refNum ) {
Create ( message_file , 0 , 'MPS ' , 'TEXT' ) ;
Try ( FSOpen ( message_file , 0 , & refNum ) ) ;
Try ( SetEOF ( refNum , 0L ) ) ;
}
if ( refNum ) {
len = * message ;
Try ( FSWrite ( refNum , & len , message + 1 ) ) ;
}
SetWindowText ( message ) ;
}
static void
MakeWindow ( ) {
window = GetNewWindow ( 128 , NULL , NULL ) ;
if ( ! window ) {
Try ( -192 ) ;
}
windowText = NewHandle ( 0L ) ;
Message ( "\pWelcome!\r" ) ;
SelectWindow ( window ) ;
ShowWindow ( window ) ;
}
void
main ( ) {
CInfoPBRec rec ;
InitMac ( ) ;
MakeWindow ( ) ;
if ( ! ReadClasses ( class_file ) ) {
rec . hFileInfo . ioNamePtr = folder_to_munge ;
rec . hFileInfo . ioVRefNum = 0 ;
rec . hFileInfo . ioDirID = 0 ;
rec . hFileInfo . ioFDirIndex = 0 ;
Try ( PBGetCatInfoSync ( & rec ) ) ;
if ( rec . hFileInfo . ioFlAttrib & 0x10 ) {
MungeFolder ( rec . hFileInfo . ioDirID ) ;
} else {
Message ( "\pIt's not a folder!" ) ;
}
} else {
Message ( "\pCannot open class file" ) ;
}
Message ( "\pClick To Exit\r" ) ;
Message ( NULL ) ;
Idle ( ) ;
}